package com.lge.remoteshot.wifidirect;

import java.util.List;

import android.content.Context;
import android.net.wifi.p2p.WifiP2pDevice;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.lge.remoteshot.R;

public class WiFiPeerListAdapter extends ArrayAdapter<WifiP2pDevice> {
	private Context context;

	private List<WifiP2pDevice> items;

	/**
	 * @param context
	 * @param textViewResourceId
	 * @param objects
	 */
	public WiFiPeerListAdapter(Context context, int textViewResourceId, List<WifiP2pDevice> objects) {
		super(context, textViewResourceId, objects);
		this.context = context;
		this.items = objects;

	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			LayoutInflater vi = (LayoutInflater) context.getSystemService(
					Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.row_devices, null);
		}
		WifiP2pDevice device = items.get(position);
		if (device != null) {
			TextView top = (TextView) v.findViewById(R.id.device_name);
			TextView bottom = (TextView) v.findViewById(R.id.device_details);
			if (top != null) {
				top.setText(device.deviceName);
			}
			if (bottom != null) {
				bottom.setText(DeviceListFragment.getDeviceStatus(device.status));
			}
		}

		return v;

	}
}